import 'package:flutter/material.dart';

void main(List<String> args) {
  runApp(const MyApp());
}

class MyApp extends StatelessWidget {
  const MyApp({super.key});

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      theme: ThemeData(useMaterial3: true),
      home: const TabarExample(),
    );
  }
}

class TabarExample extends StatelessWidget {
  const TabarExample({super.key});

  @override
  Widget build(BuildContext context) {
    return DefaultTabController(
        initialIndex: 1,
        length: 3,
        child: Scaffold(
          appBar: appBar(),
          body: tabBarView(),
        ));
  }

  PreferredSizeWidget appBar() {
    return AppBar(
        title: const Text('TabBar Sample'),
        bottom: const TabBar(tabs: <Widget>[
          Tab(
            icon: Icon(Icons.cloud_outlined),
            text: '云朵',
          ),
          Tab(
            icon: Icon(Icons.beach_access_sharp),
            text: '雨伞',
          ),
          Tab(
            icon: Icon(Icons.brightness_5_sharp),
            text: '太阳',
          )
        ]));
  }

  Widget tabBarView() {
    return const TabBarView(children: <Widget>[
      Center(
        child: Text('云朵'),
      ),
      Center(
        child: Text('雨伞'),
      ),
      Center(
        child: Text('太阳'),
      )
    ]);
  }
}
